//
//  VersionImageView.m
//  Book Editor
//
//  Created by Chris Karr on 7/7/08.
//  Copyright 2008 Northwestern University. All rights reserved.
//

#import "VersionImageView.h"


@implementation VersionImageView

- (id)initWithFrame:(NSRect)frame 
{
    self = [super initWithFrame:frame];

    if (self) 
	{
        // Initialization code here.
    }

    return self;
}

- (NSDragOperation) draggingEntered:(id <NSDraggingInfo>) sender
{
	NSLog (@"dragging entered");
	
	if (![self isEnabled])
		return NSDragOperationNone;
	
	NSPasteboard * paste = [sender draggingPasteboard];
	
    NSArray * types = [NSArray arrayWithObject:NSFilenamesPboardType];
	
    NSString * desiredType = [paste availableTypeFromArray:types];
	
	if (desiredType != nil)
		return NSDragOperationCopy;
		
	return NSDragOperationNone;
}

/* - (void) draggingExited:(id <NSDraggingInfo>) sender
{
	[super draggingExited:sender];
}

- (NSDragOperation) draggingUpdated:(id <NSDraggingInfo>) sender
{
	return [super draggingUpdated:sender];
}

- (BOOL) prepareForDragOperation:(id <NSDraggingInfo>) sender
{
	return [super prepareForDragOperation:sender];
} */

- (BOOL) performDragOperation:(id <NSDraggingInfo>) sender
{
    NSPasteboard * paste = [sender draggingPasteboard];

    NSArray * types = [NSArray arrayWithObject:NSFilenamesPboardType];

    NSString * desiredType = [paste availableTypeFromArray:types];
	
	if (desiredType != nil)
	{
		NSArray * fileArray = [paste propertyListForType:@"NSFilenamesPboardType"];
		NSString * path = [fileArray objectAtIndex:0];

		[versionController setFile:path];

		return YES;
    }

    return NO;
}

@end
